package com.boat.starter.mockit;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.boat.starter.mockit.constant.MockConsts;
import com.boat.starter.mockit.filter.MockFilter;
import com.boat.starter.mockit.props.MockProperties;
import com.boat.starter.mockit.service.MockitCallService;
import com.boat.starter.mockit.service.MockitMatchService;

import lombok.extern.slf4j.Slf4j;

/**
 * mock自动配置
 * 
 * @author 周江
 *
 */
@Slf4j
@Configuration
@ConditionalOnProperty(prefix = MockConsts.PREFIX, value = "type", havingValue = MockConsts.MockType.MOCKIT)
@EnableConfigurationProperties(value = { MockProperties.class })
public class MockitAutoConfiguration implements InitializingBean{
	
	@Bean
	public MockitCallService mockitCallService(MockProperties mockProperties) {
		return new MockitCallService(mockProperties.getMockit());
	}

	@Bean
	public MockitMatchService mockitMatchService(MockProperties mockProperties) {
		return new MockitMatchService(mockProperties.getMockit());
	}

	@Bean
	public MockFilter mockFilter(MockProperties mockProperties, MockitMatchService mockitMatchService,
			MockitCallService mockitCallService) {
		return new MockFilter(mockProperties.getMockit(), mockitMatchService, mockitCallService);
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		log.info("boat-starter-mockit加载成功");
	}
	
}
